import axios from'./axios'
import {header1,header2} from './common'
import {category_list,category_add,category_update,category_delete,category_search} from './../api/category'

export function categoryList(searchName?: string){
    const params: any = {}
    if (searchName) {
        params.where = JSON.stringify({
            name: {
                $regex: searchName,
                $options: 'i'
            }
        })
    }
    return axios({
        method:'get',
        url: category_list,
        params,
        headers:{
            ...header1,
        }
    })
}
// 新增分类
export function categoryAdd(data: any) {
  return axios({
    method: 'post',
    url: category_add,
    data,
    headers: {
      ...header2,
    }
  })
}
//编辑
export function categoryEdit(objectId:string,data:any){
    return axios({
    method:'put',
    data,
    url:category_update+'/'+objectId,
    headers:{
        ...header2,
    }
})
}
//删除
export function categoryDel(objectId:string){
    return axios({
    method:'delete',
    url:category_delete+"/"+objectId,
    headers:{
        ...header2,
    }
})
}
